﻿using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ledict.ConditionExtract.Frm.DataProcess
{
    public partial class TYCSelect : Form
    {
        SYS_SiftBdSynBLL ssbs = new SYS_SiftBdSynBLL();
        SYS_SiftWordBLL sswb = new SYS_SiftWordBLL();
        public TYCSelect(int type)
        {
            InitializeComponent();
            dgvSCC.AutoGenerateColumns = false;
            dgvSCC.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvTYC.AutoGenerateColumns = false;
            dgvTYC.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            if (type == 1)
            {
                this.Text = "筛选同义词";
                dgvTYC.Visible = true;
                dgvSCC.Visible = false;
                dgvTYC.Dock = DockStyle.Fill;
                GetTycData();
            }
            else if (type == 2)
            {
                dgvSCC.Visible = true;
                dgvTYC.Visible = false;
                dgvSCC.Dock = DockStyle.Fill;
                this.Text = "筛除词库";
                GetSCData();
            }

        }

        /// <summary>
        /// 获取同义词
        /// </summary>
        public void GetTycData()
        {
            DataTable dt = ssbs.GetSiftBdSyn();
            if (dt != null && dt.Rows.Count > 0)
            {
                dgvTYC.DataSource = dt;
            }
            else
            {
                DataTable dtt = (DataTable)dgvTYC.DataSource;
                if (dtt != null)
                { dtt.Rows.Clear(); }
                dgvTYC.DataSource = dtt;
            }
        }

        /// <summary>
        /// 获取筛除词库
        /// </summary>
        public void GetSCData()
        {
            DataTable dt = sswb.GetSiftWord();
            if (dt != null && dt.Rows.Count > 0)
            {
                dt = PublicMethod.AddDataTableNum(dt);
                dgvSCC.DataSource = dt;
            }
            else
            {
                DataTable dtt = (DataTable)dgvSCC.DataSource;
                if (dtt != null)
                { dtt.Rows.Clear(); }
                dgvSCC.DataSource = dtt;
            }
        }

        private void dgvTYC_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                //4对勾5×
                if (e.ColumnIndex == 2)
                {
                    var checkCellRight = (DataGridViewCheckBoxCell)dgvTYC.Rows[e.RowIndex].Cells["Check"];

                    if (checkCellRight.Value != DBNull.Value && Convert.ToBoolean(checkCellRight.Value))
                    {
                        checkCellRight.Value = false;
                    }
                    else
                    {
                        checkCellRight.Value = true;
                    }


                    if (Convert.ToBoolean(checkCellRight.Value))
                    {
                        string sbID = dgvTYC.Rows[e.RowIndex].Cells["SB_ID"].Value.ToString();
                        if (ssbs.Delete(sbID))
                        {
                            MessageBox.Show("删除成功！");
                            GetTycData();
                        }
                    }
                }
            }
        }

        private void dgvSCC_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                //4对勾5×
                if (e.ColumnIndex == 2)
                {
                    var checkCellRight = (DataGridViewCheckBoxCell)dgvSCC.Rows[e.RowIndex].Cells["Check1"];

                    if (checkCellRight.Value != DBNull.Value && Convert.ToBoolean(checkCellRight.Value))
                    {
                        checkCellRight.Value = false;
                    }
                    else
                    {
                        checkCellRight.Value = true;
                    }


                    if (Convert.ToBoolean(checkCellRight.Value))
                    {
                        string swID = dgvSCC.Rows[e.RowIndex].Cells["SW_ID"].Value.ToString();
                        if (sswb.Delete(swID))
                        {
                            MessageBox.Show("删除成功！");
                            GetSCData();
                        }
                    }
                }
            }

        }
    }
}
